jQuery.validator.setDefaults({
	ignore : ".ignore",
	errorElement : "em",
	errorPlacement : function(error, element) {
		error.addClass("help-block");
		if (element.parent().is('.input-group')) {
			element.parent().parent().append(error);
		} else {
			element.parent().append(error);
		}
	},
	highlight : function(element, errorClass, validClass) {
		$(element).parents(".form-group").addClass("has-error");
	},
	unhighlight : function(element, errorClass, validClass) {
		$(element).parents(".form-group").removeClass("has-error");
	},
	submitHandler : function(form) {
		Ajax.form(form, function(result) {
			$(form).trigger('submit-success', result);
		}, function(err) {
			$(form).trigger('submit-error', err);
		});
	}
})
// 手机号码验证
jQuery.validator.addMethod("isMobile", function(value, element) {
	return this.optional(element) || /^[1][3,4,5,6,7,8][0-9]{9}$/.test(value);
}, "请正确填写手机号码");

// 电话号码验证
jQuery.validator.addMethod("isPhone", function(value, element) {
	var tel = /^([0-9]{3,4}-)?[0-9]{7,9}$/;
	return this.optional(element) || (tel.test(value));
}, "请正确填写电话号码");

// 联系电话(手机/电话皆可)验证
jQuery.validator.addMethod("isTel", function(value, element) {
	var mobile = /^[1][3,4,5,6,7,8][0-9]{9}$/;
	var tel = /^([0-9]{3,4}-)?[0-9]{7,9}$/;
	return this.optional(element) || tel.test(value) || mobile.test(value);
}, "请正确填写联系方式");

jQuery.validator.addMethod('isPassword', function(value, element) {
	return /^[\@A-Za-z0-9\!\#\$\%\^\&\*\.\~]{6,22}$/.test(value);
}, '密码必须是6-22位,无特殊字符');

jQuery.validator.addMethod('isIdCard', function(value, element) {
	return /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/.test(value) || /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/.test(value);
}, '请输入身份证号码');

jQuery.validator.addMethod("isName", function(value, element) {
	return this.optional(element) || (value.length >= 2 && value.length <= 15 && /^[\u4e00-\u9fa5]+$/.test(value));
}, "请输入正确的姓名");
